//
//  HELVedioAndCourseControllVC.m
//  HandheldELearn
//
//  Created by wsj2015 on 16/8/2.
//  Copyright © 2016年 陈武琦. All rights reserved.
//

#import "HELVedioAndCourseControllVC.h"
#import "HMSegmentedControl.h"
#import "HELCourseVedioVC.h"
#import "HELCourseListVC.h"
#import "YSLContainerViewController.h"

@interface HELVedioAndCourseControllVC ()<YSLContainerViewControllerDelegate>

@property (nonatomic,  strong) HELCourseVedioVC *vedioListVC;
@property (nonatomic,  strong) HELCourseListVC *courseListVC;

@property (nonatomic,  strong) HMSegmentedControl *segmenet;


@property (nonatomic,  assign) NSInteger currentItem;

@property (nonatomic,  strong) YSLContainerViewController *containVC;



@end

@implementation HELVedioAndCourseControllVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (void)configUI{

    [self setNav];
    self.vedioListVC =[HELCourseVedioVC new];
    self.courseListVC =[HELCourseListVC new];
    self.courseListVC.parentNav = self.navigationController;
    YSLContainerViewController *containerVC = [[YSLContainerViewController alloc]initWithControllers:@[self.vedioListVC,self.courseListVC]
                                                                                        topBarHeight:-40
                                                                                parentViewController:self];
    containerVC.delegate = self;

    [self.view addSubview:containerVC.view];
    self.containVC = containerVC;

   
    self.currentItem =0;
    
}

#pragma mark -- YSLContainerViewControllerDelegate
- (void)containerViewItemIndex:(NSInteger)index currentController:(UIViewController *)controller
{
    
    self.segmenet.selectedSegmentIndex = index;
    //    NSLog(@"current Index : %ld",(long)index);
    //    NSLog(@"current controller : %@",controller);
    //    [controller viewWillAppear:YES];
}
- (void)setNav{
    HMSegmentedControl *segmentedControl3 = [[HMSegmentedControl alloc] initWithSectionTitles:@[@"视频", @"课件"]];
    [segmentedControl3 setFrame:CGRectMake(0, 0, 140, 44)];
    defineWeakSelf;
    [segmentedControl3 setIndexChangeBlock:^(NSInteger index) {
        weakSelf.currentItem = index;
        [weakSelf.containVC.contentScrollView setContentOffset:CGPointMake(index * weakSelf.containVC.contentScrollView.frame.size.width, 0.) animated:YES];
        
    }];
    segmentedControl3.selectionIndicatorHeight = 1.0f;
    segmentedControl3.backgroundColor = [UIColor clearColor];
    segmentedControl3.titleTextAttributes = @{NSForegroundColorAttributeName :  [UIColor colorWithWhite:.8 alpha:1]};
    segmentedControl3.selectedTitleTextAttributes =@{NSForegroundColorAttributeName : [UIColor colorWithWhite:1 alpha:1]};
    segmentedControl3.selectionIndicatorColor = [UIColor whiteColor];
    segmentedControl3.selectionStyle = HMSegmentedControlSelectionStyleTextWidthStripe;
    segmentedControl3.selectedSegmentIndex = 0;
    segmentedControl3.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
    segmentedControl3.shouldAnimateUserSelection = YES;
    segmentedControl3.selectionIndicatorEdgeInsets = UIEdgeInsetsMake(0, 0, -4, 0);
    segmentedControl3.tag = 2;
    self.segmenet = segmentedControl3;
    
    self.navigationItem.titleView = segmentedControl3;
}

//- (void)changeView{
//    
//    UIView *fromView;
//    UIView *toView;
//    if ( self.currentItem == 0) {
//        toView = self.vedioListVC.view;
//        fromView = self.courseListVC.view;
//       
//    }else{
//        fromView = self.vedioListVC.view;
//        toView = self.courseListVC.view;
//       
//    }
//    defineWeakSelf;
//    [UIView transitionFromView:fromView toView:toView duration:.35f options:UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionLayoutSubviews completion:^(BOOL finished) {
//        weakSelf.currentItem = !weakSelf.currentItem;
//    }];
//}


@end
